package com.servlet.user;

import com.dao.UserDao;
import com.dao.UserInfo;
import com.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author admin
 */
@WebServlet(name = "UserSelectOneServlet",urlPatterns = "/UserSelectOneServlet.filter")
public class UserSelectOneServlet extends HttpServlet {
//    private String encoding;


    private UserDao userDao = new UserInfo();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String u_id = request.getParameter("u_id");
        System.out.println("UserSelectOneServlet");
        try {
            User updateUser = userDao.selectOneUser(Integer.parseInt(u_id));
            System.out.println(updateUser.toString());
            request.setAttribute("updateUser",updateUser);
            request.getRequestDispatcher("/WEB-INF/page/user.jsp").forward(request,response);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
